package com.usian.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.wemedia.WemediaUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.WemediaUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * ClassName: WmUserController
 * Author:   WGG
 * Date:    2022-11-2022/11/14-12:36
 * Version: 1.0
 * Description:
 */
@RestController
@RequestMapping("/wemedia/api/v1")
public class WemediaUserController implements WemediaUserControllerApi {

    @Autowired
    private WemediaUserService wemediaUserService;

    /**
     * 根据名称查询自媒体人
     * @param name
     * @return
     */
    @Override
    @PostMapping("/findByName/{name}")
    public WmUser findByName(@PathVariable String name) {
        if (StringUtils.isNotEmpty(name)){
            WmUser wmUser = wemediaUserService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName,name));
            return wmUser;
        }
        return null;
    }
    /**
     * 添加自媒体人
     * @param wmUser
     * @return
     */
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmUser wmUser) {
        wemediaUserService.save(wmUser);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
